package Text_11;

import java.util.ArrayList;
public class ArrPhone {

	public static void main(String[] args) {
		ArrayList<Phone> list = new ArrayList<>();  

		Phone p1 = new Phone("小米",1000);
		Phone p2 = new Phone("苹果",8000);
		Phone p3 = new Phone("锤子",2999);
		//添加到集合中
		list.add(p1);
		list.add(p2);
		list.add(p3);
		ArrayList<Phone> restlist = infor(list,3000);
		for(int i=0;i<restlist.size();i++) {
			Phone ph1 = restlist.get(i);
			System.out.println(ph1.getBrand()+" "+ph1.getPrice());
		}
	}

	public static ArrayList<Phone> infor(ArrayList<Phone> list,int price) {
		//定义一个集合，用来存储小于price的手机信息
		ArrayList<Phone> restlist = new ArrayList<>();
		for(int i=0;i<list.size();i++) {
			//获取集合中的每一个元素
			Phone ph = list.get(i);
			//获取每个元素中的价格
			int ph1 = ph.getPrice();
			if(ph1<price) {
				restlist.add(ph);
			}
		}
		return restlist;

	}

}
